package quadric_ecuation;

public class QuadricEcuation {
	
	private double a;
	private double b;
	private double c;
	private double x1;
	private double x2;
	private double discriminant;
	
	public QuadricEcuation (double a, double b, double c){
		this.a = a;
		this.b = b;
		this.c = c;
		solveEcuation();
	}
	
	public boolean hasSolutions(){
		discriminant = b * b - 4 * a * c; 
		return discriminant > 0;
	}

	private void solveEcuation(){
		if(hasSolutions()){
			x1 = (-b - Math.sqrt(discriminant))/(2*a);
			x2 = (-b + Math.sqrt(discriminant))/(2*a);
		}
		else {
			x1=0;
			x2=0;
		}
	}
	
	public double getSolution1(){
		return Math.min(x1, x2);
	}
	
	public double getSolution2(){
		return Math.max(x1, x2);
	}
	
}
